package com.sean.findme.near;

import java.util.HashMap;
import java.util.List;

import android.app.ActivityGroup;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sean.findme.FmActivityMgrCtrller;
import com.sean.findme.R;
import com.sean.findme.dbentrys.ShopInfoItem;

public class NearShopInfoAdapter extends BaseAdapter{
	
	private Context mContext;
	private List<ShopInfoItem> list = null;
	
	

	public NearShopInfoAdapter(Context mContext, List<ShopInfoItem> list) {
		super();
		this.mContext = mContext;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.near_list_item, null);
		TextView nameView = (TextView)layout.findViewById(R.id.near_list_item_name);
		nameView.setText(list.get(position).getName());
		
		TextView disView = (TextView)layout.findViewById(R.id.near_list_item_dis);
		disView.setText(list.get(position).getLatitude().toString());
		
		TextView addrView = (TextView)layout.findViewById(R.id.near_list_item_addr);
		addrView.setText(list.get(position).getAddress());
		
		layout.setOnClickListener(new MyItemClickListener(position));
		
		
		return layout;
	}
	
	public class MyItemClickListener implements View.OnClickListener
	{
		private int index = 0;
		
		public MyItemClickListener(int index) {
			super();
			this.index = index;
		}

		@Override
		public void onClick(View v) {
			HashMap<String,String> map = new HashMap<String,String>();
			map.put("id", String.format("%d", index));
			FmActivityMgrCtrller.getInstance(null).getCurActivityMgr().JmpActivity(mContext, NearShopActivity.class, (ActivityGroup)(((NearActivity)mContext).getParent()), map, true);
			
		}
		
	}

}
